<!DOCTYPE html>
<html prefix="og: http://ogp.me/ns# article: http://ogp.me/ns/article# " lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="Tj2's Blog">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>绿萝间 (old posts, page 2) | 绿萝间</title>
<link href="assets/css/all-nocdn.css" rel="stylesheet" type="text/css">
<link href="assets/css/ipython.min.css" rel="stylesheet" type="text/css">
<link href="assets/css/nikola_ipython.css" rel="stylesheet" type="text/css">
<meta name="theme-color" content="#5670d4">
<meta name="generator" content="Nikola (getnikola.com)">
<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.xml">
<link rel="canonical" href="https://muxuezi.github.io/index-2.html">
<link rel="prev" href="index-3.html" type="text/html">
<link rel="next" href="index-1.html" type="text/html">
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: true
    },
    displayAlign: 'center', // Change this to 'center' to center equations.
    "HTML-CSS": {
        styles: {'.MathJax_Display': {"margin": 0}}
    }
});
</script><!--[if lt IE 9]><script src="assets/js/html5.js"></script><![endif]-->
</head>
<body>
<a href="#content" class="sr-only sr-only-focusable">Skip to main content</a>

<!-- Menubar -->

<nav class="navbar navbar-inverse navbar-static-top"><div class="container">
<!-- This keeps the margins nice -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar" aria-controls="bs-navbar" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="https://muxuezi.github.io/">

                <span id="blog-title">绿萝间</span>
            </a>
        </div>
<!-- /.navbar-header -->
        <div class="collapse navbar-collapse" id="bs-navbar" aria-expanded="false">
            <ul class="nav navbar-nav">
<li>
<a href="archive.html">Archive</a>
                </li>
<li>
<a href="categories/">Tags</a>
                </li>
<li>
<a href="rss.xml">RSS feed</a>

                
            </li>
</ul>
<ul class="nav navbar-nav navbar-right"></ul>
</div>
<!-- /.navbar-collapse -->
    </div>
<!-- /.container -->
</nav><!-- End of Menubar --><div class="container" id="content" role="main">
    <div class="body-content">
        <!--Body content-->
        <div class="row">
            
            

    
<div class="postindex">
    <article class="h-entry post-text"><header><h1 class="p-name entry-title"><a href="posts/python-ruby.html" class="u-url">python-ruby</a></h1>
        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                Tao Junjie
            </span></p>
            <p class="dateline"><a href="posts/python-ruby.html" rel="bookmark"><time class="published dt-published" datetime="2010-01-01T13:44:27+08:00" title="2010-01-01 13:44">2010-01-01 13:44</time></a></p>
        </div>
    </header><div class="p-summary entry-summary">
    <p class="more"><a href="posts/python-ruby.html">Read more…</a></p>
    </div>
    </article><article class="h-entry post-text"><header><h1 class="p-name entry-title"><a href="posts/python-unicode.html" class="u-url">python-unicode</a></h1>
        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                Tao Junjie
            </span></p>
            <p class="dateline"><a href="posts/python-unicode.html" rel="bookmark"><time class="published dt-published" datetime="2010-01-01T13:44:27+08:00" title="2010-01-01 13:44">2010-01-01 13:44</time></a></p>
        </div>
    </header><div class="p-summary entry-summary">
    <div>
<p></p>
<p>unicode一直是头疼事儿，今天清理一下。
</p>
<ol>
<li>ipython notebook默认编码 'Ascii'</li>
    <li>输入open(f,'r')，如果有中文，需要转换才能使用</li>
    <li>网络数据如果要写入文件open(f,'w')，需要encode转为utf8</li>
</ol>
<p>只要是中文使用出现出入"Ascii ....Unicode"，就转换下：</p>
<p>addressto = addressto.decode("utf-8")</p>
<p>彻底改变编码：</p>
<ol>
<li>python3，都是utf-8</li>
    <li>通过sys改变编码，可以在cmd里面用，notebook不支持</li>
</ol>
<div class="dp-highlighter nogutter">

<ol class="dp-py" start="0">
<li class="alt"><span class="comment"># -*- coding: utf-8 -*-</span></li>
    <li>
<span class="keyword">import</span> <span class="commonlibs">sys</span>
</li>
    <li class="alt">
<span class="builtins">reload</span>(<span class="commonlibs">sys</span>)</li>
    <li>
<span class="commonlibs">sys</span>.setdefaultencoding('utf-8')</li>
    <li class="alt"><span class="comment"># print sys.getdefaultencoding()</span></li>
</ol>
</div>

<p></p>
</div>
    </div>
    </article><article class="h-entry post-text"><header><h1 class="p-name entry-title"><a href="posts/raw_input.html" class="u-url">raw_input</a></h1>
        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                Tao Junjie
            </span></p>
            <p class="dateline"><a href="posts/raw_input.html" rel="bookmark"><time class="published dt-published" datetime="2010-01-01T13:44:27+08:00" title="2010-01-01 13:44">2010-01-01 13:44</time></a></p>
        </div>
    </header><div class="p-summary entry-summary">
    <div>
<p></p>
<p>#On windows
len_in = raw_input(u"请设置下载位置n".encode('GBK')) </p>
<p>if len_in == '':print(u'设置完毕')</p>
<p>ft = driver.find_element_by_id('downloadLocationPath')</p>
</div>
    </div>
    </article><article class="h-entry post-text"><header><h1 class="p-name entry-title"><a href="posts/regex.html" class="u-url">regex</a></h1>
        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                Tao Junjie
            </span></p>
            <p class="dateline"><a href="posts/regex.html" rel="bookmark"><time class="published dt-published" datetime="2010-01-01T13:44:27+08:00" title="2010-01-01 13:44">2010-01-01 13:44</time></a></p>
        </div>
    </header><div class="p-summary entry-summary">
    <div>
<p></p>
<p>用于字符串处理、表单验证等场合，实用高效。现将一些常用的表达式收集于此，以备不时之需。</p>
<p>匹配中文字符的正则表达式： [u4e00-u9fa5]</p>
<p>评注：匹配中文还真是个头疼的事，有了这个表达式就好办了</p>
<p>匹配双字节字符(包括汉字在内)：[^x00-xff]</p>
<p>评注：可以用来计算字符串的长度（一个双字节字符长度计2，ASCII字符计1）</p>
<p>匹配空白行的正则表达式：ns*r</p>
<p>评注：可以用来删除空白行</p>
<p>匹配HTML标记的正则表达式：]<em>&gt;.</em>?1&gt;|&lt;.&gt;</p>
<p>评注：网上流传的版本太糟糕，上面这个也仅仅能匹配部分，对于复杂的嵌套标记依旧无能为力</p>
<p>匹配首尾空白字符的正则表达式：^s<em>|s</em>$</p>
<p>评注：可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等)，非常有用的表达式</p>
<p>匹配Email地址的正则表达式：w+([-+.]w+)<em>@w+([-.]w+)</em>.w+([-.]w+)*</p>
<p>评注：表单验证时很实用</p>
<p>匹配网址URL的正则表达式：[a-zA-z]+://[^s]*</p>
<p>评注：网上流传的版本功能很有限，上面这个基本可以满足需求</p>
<p>匹配帐号是否合法(字母开头，允许5-16字节，允许字母数字下划线)：^[a-zA-Z][a-zA-Z0-9_]{4,15}$</p>
<p>评注：表单验证时很实用</p>
<p>匹配国内电话号码：d{3}-d{8}|d{4}-d{7}</p>
<p>评注：匹配形式如 0511-4405222 或 021-87888822</p>
<p>匹配腾讯QQ号：[1-9][0-9]{4,}</p>
<p>评注：腾讯QQ号从10000开始</p>
<p>匹配中国邮政编码：[1-9]d{5}(?!d)</p>
<p>评注：中国邮政编码为6位数字</p>
<p>匹配身份证：d{15}|d{18}</p>
<p>评注：中国的身份证为15位或18位</p>
<p>匹配ip地址：d+.d+.d+.d+</p>
<p>评注：提取ip地址时有用</p>
<p>匹配特定数字：</p>
<p>^[1-9]d*$　 　 //匹配正整数</p>
<p>^-[1-9]d*$ 　 //匹配负整数</p>
<p>^-?[1-9]d*$　　 //匹配整数</p>
<p>^[1-9]d*|0$　 //匹配非负整数（正整数 + 0）</p>
<p>^-[1-9]d*|0$　　 //匹配非正整数（负整数 + 0）</p>
<p>^[1-9]d<em>.d</em>|0.d<em>[1-9]d</em>$　　 //匹配正浮点数</p>
<p>^-([1-9]d<em>.d</em>|0.d<em>[1-9]d</em>)$　 //匹配负浮点数</p>
<p>^-?([1-9]d<em>.d</em>|0.d<em>[1-9]d</em>|0?.0+|0)$　 //匹配浮点数</p>
<p>^[1-9]d<em>.d</em>|0.d<em>[1-9]d</em>|0?.0+|0$　　 //匹配非负浮点数（正浮点数 + 0）</p>
<p>^(-([1-9]d<em>.d</em>|0.d<em>[1-9]d</em>))|0?.0+|0$　　//匹配非正浮点数（负浮点数 + 0）</p>
<p>评注：处理大量数据时有用，具体应用时注意修正</p>
<p>匹配特定字符串：</p>
<p>^[A-Za-z]+$　　//匹配由26个英文字母组成的字符串</p>
<p>^[A-Z]+$　　//匹配由26个英文字母的大写组成的字符串</p>
<p>^[a-z]+$　　//匹配由26个英文字母的小写组成的字符串</p>
<p>^[A-Za-z0-9]+$　　//匹配由数字和26个英文字母组成的字符串</p>
<p>^w+$　　//匹配由数字、26个英文字母或者下划线组成的字符串</p>
</div>
    </div>
    </article><article class="h-entry post-text"><header><h1 class="p-name entry-title"><a href="posts/ruby-on-rails-with-ruby2-0.html" class="u-url">ruby-on-rails-with-ruby2-0</a></h1>
        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                Tao Junjie
            </span></p>
            <p class="dateline"><a href="posts/ruby-on-rails-with-ruby2-0.html" rel="bookmark"><time class="published dt-published" datetime="2010-01-01T13:44:27+08:00" title="2010-01-01 13:44">2010-01-01 13:44</time></a></p>
        </div>
    </header><div class="p-summary entry-summary">
    <div>
<p></p>
<ol>
<li>linux mint 15 install ruby 2.0
<ul>
<li>sudo apt-get -y update</li>
    <li>sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev</li>
    <li>cd /tmp</li>
    <li>wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.bz2</li>
    <li>tar -xvjf ruby-2.0.0-p0.tar.bz2</li>
    <li>cd ruby-2.0.0-p0/</li>
    <li>./configure --prefix=/usr/local</li>
    <li>make</li>
    <li>sudo make install</li>
</ul>
<p></p>
</li>
    <li> install sqlite3
<ul>
<li>sudo apt-get install sqlite3 libsqlite3-dev</li>
</ul>
<p></p>
</li>
    <li> install rails
<ul>
<li>sudo apt-get install nodejs</li>
    <li>sudo gem install rails</li>
</ul>
</li>

<p></p>
</ol>
</div>
    </div>
    </article><article class="h-entry post-text"><header><h1 class="p-name entry-title"><a href="posts/selenium-jump-update.html" class="u-url">selenium-jump-update</a></h1>
        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                Tao Junjie
            </span></p>
            <p class="dateline"><a href="posts/selenium-jump-update.html" rel="bookmark"><time class="published dt-published" datetime="2010-01-01T13:44:27+08:00" title="2010-01-01 13:44">2010-01-01 13:44</time></a></p>
        </div>
    </header><div class="p-summary entry-summary">
    <div>
<p></p>
<p>运行js代码实现滚动条效果
driver.execute_script("window.scrollTo(0, document.body.scrollHeight/1.8);")</p>
<p>跳转iframe，beautifulsoup遇到iframe时需要用</p>
<p>driver.switch_to_frame('frame_content')</p>
<p>关闭</p>
<p>driver.quit()</p>
<p>一定要及时更新</p>
<p><a title="selenium-python" href="http://selenium-python.readthedocs.org/en/latest/index.html" target="_blank">selenium-python</a></p>
<p><a title="Selenium Python" href="http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html" target="_blank">selenuim2.0-py-doc</a></p>
<p><a title="chromedriver" href="http://chromedriver.storage.googleapis.com/index.html" target="_blank">chromedriver64</a></p>
</div>
    </div>
    </article><article class="h-entry post-text"><header><h1 class="p-name entry-title"><a href="posts/shell-keywords.html" class="u-url">shell-keywords</a></h1>
        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                Tao Junjie
            </span></p>
            <p class="dateline"><a href="posts/shell-keywords.html" rel="bookmark"><time class="published dt-published" datetime="2010-01-01T13:44:27+08:00" title="2010-01-01 13:44">2010-01-01 13:44</time></a></p>
        </div>
    </header><div class="p-summary entry-summary">
    <div>
<p></p>
<p>在目录下所有ltestats文件中找关键词nackcnt:
find . -name '<em>ltestats</em>' -print | grep -R -i -n 'nackcnt'&gt;nackcnt</p>
</div>
    </div>
    </article><article class="h-entry post-text"><header><h1 class="p-name entry-title"><a href="posts/shell-postfix.html" class="u-url">shell-postfix</a></h1>
        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                Tao Junjie
            </span></p>
            <p class="dateline"><a href="posts/shell-postfix.html" rel="bookmark"><time class="published dt-published" datetime="2010-01-01T13:44:27+08:00" title="2010-01-01 13:44">2010-01-01 13:44</time></a></p>
        </div>
    </header><div class="p-summary entry-summary">
    <div>
<p></p>
<p>有一批文件，以 .bak结尾，现在想把这些 .bak 统统去掉。
rename     's/.bak$//'       *.bak</p>
</div>
    </div>
    </article><article class="h-entry post-text"><header><h1 class="p-name entry-title"><a href="posts/sublime_text-package-control.html" class="u-url">sublime_text-package-control</a></h1>
        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                Tao Junjie
            </span></p>
            <p class="dateline"><a href="posts/sublime_text-package-control.html" rel="bookmark"><time class="published dt-published" datetime="2010-01-01T13:44:27+08:00" title="2010-01-01 13:44">2010-01-01 13:44</time></a></p>
        </div>
    </header><div class="p-summary entry-summary">
    <div>
<p></p>
<p>package control</p>
<p>import urllib2,os; pf='Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler( ))); open( os.path.join( ipp, pf), 'wb' ).write( urllib2.urlopen( 'http://sublime.wbond.net/' +pf.replace( ' ','%20' )).read()); print( 'Please restart Sublime Text to finish installation')</p>
<p>ppa install</p>
<p>sudo add-apt-repository ppa:webupd8team/sublime-text-2</p>
<p>sudo apt-get update</p>
<p>sudo apt-get install sublime-text</p>
</div>
    </div>
    </article><article class="h-entry post-text"><header><h1 class="p-name entry-title"><a href="posts/tdlte-4g-card.html" class="u-url">tdlte-4g-card</a></h1>
        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                Tao Junjie
            </span></p>
            <p class="dateline"><a href="posts/tdlte-4g-card.html" rel="bookmark"><time class="published dt-published" datetime="2010-01-01T13:44:27+08:00" title="2010-01-01 13:44">2010-01-01 13:44</time></a></p>
        </div>
    </header><div class="p-summary entry-summary">
    <div>
<p></p>
<p>移动4G卡TD-LTE目前营业厅免费换，真是企业良心啊。不用换号，保留原2G套餐，直接2G变4G，Perfect</p>
</div>
    </div>
    </article>
</div>

        <nav class="postindexpager"><ul class="pager">
<li class="previous">
                <a href="index-3.html" rel="prev">Newer posts</a>
            </li>
            <li class="next">
                <a href="index-1.html" rel="next">Older posts</a>
            </li>
        </ul></nav>
</div>
        <!--End of body content-->

        <footer id="footer">
            Contents © 2017         <a href="mailto:muxuezi@gmail.com">Tao Junjie</a> - Powered by         <a href="https://getnikola.com" rel="nofollow">Nikola</a>         
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0">
<img alt="Creative Commons License BY-NC-SA" style="border-width:0; margin-bottom:12px;" src="http://i.creativecommons.org/l/by-nc-sa/4.0/80x15.png"></a>
            
        </footer>
</div>
</div>


            <script src="assets/js/all-nocdn.js"></script><script>$('a.image-reference:not(.islink) img:not(.islink)').parent().colorbox({rel:"gal",maxWidth:"100%",maxHeight:"100%",scalePhotos:true});</script><!-- fancy dates --><script>
    moment.locale("en");
    fancydates(0, "YYYY-MM-DD HH:mm");
    </script><!-- end fancy dates --><script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-51330059-1', 'auto');
  ga('send', 'pageview');

</script>
</body>
</html>
